<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="../../React/react.development.js"></script>
  <script src="../../React/react-dom.development.js"></script>
  <script src="../../React/babel.min.js"></script>
  <title>Document</title>
</head>

<body>
  <div id="app"></div>
  <script type="text/babel">
    // 1.创建组件
    class App extends React.Component {
      state = {
        count: 0,
        isHot: true
      }
      // 这里的this都指向实例化对象
      render() {
        // 拿到值
        const { count, inHot } = this.state
        return <div>
          <button onClick={this.add}>+</button>
          <p>{count}</p>
          <button onClick={this.sub}>-</button>
          <br />
          <button onClick={this.cut}>切换天气</button>
          <p>{isHot ? '热热' : '冷冷'}</p>
        </div>
      }
      // 加的函数 修改实例化对象身上的属性的值 再重新渲染上去
      add = () => {
        // 先获取需要改变的值
        let { count } = this.state
        this.setState({ count: ++count })
      }
      // 减的函数
      sub = () => {
        // 先获取需要改变的值
        let { count } = this.state
        this.setState({ count: --count })
      }
      // 切换的函数
      cut = () => {
        let { isHot } = this.state
        this.setState({ isHot: !isHot })
      }
    }
    // 渲染页面
    ReactDOM.createRoot(document.getElementById('app')).render(<App />)
  </script>
</body>

</html>